{% extends "base.html" %}

{% block title %}信访统计 - {{ app_name }}{% endblock %}

{% block page_title %}信访统计{% endblock %}

{% block page_subtitle %}信访件数据统计分析{% endblock %}

{% block content %}
<div class="fade-in">
    <!-- 统计卡片 -->
    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
        <div class="stat-card bg-gradient-to-br from-blue-500 to-blue-600 rounded-xl p-6 text-white">
            <div class="flex items-center justify-between mb-4">
                <div class="w-12 h-12 bg-white bg-opacity-20 rounded-lg flex items-center justify-center">
                    <i class="fas fa-file-alt text-2xl"></i>
                </div>
                <span class="text-3xl font-bold">456</span>
            </div>
            <p class="text-blue-100">总信访数量</p>
            <p class="text-xs text-blue-200 mt-2">
                <i class="fas fa-arrow-up mr-1"></i>
                较上月增长 8%
            </p>
        </div>

        <div class="stat-card bg-gradient-to-br from-green-500 to-green-600 rounded-xl p-6 text-white">
            <div class="flex items-center justify-between mb-4">
                <div class="w-12 h-12 bg-white bg-opacity-20 rounded-lg flex items-center justify-center">
                    <i class="fas fa-check-circle text-2xl"></i>
                </div>
                <span class="text-3xl font-bold">312</span>
            </div>
            <p class="text-green-100">已处理</p>
            <p class="text-xs text-green-200 mt-2">
                处理率 68.4%
            </p>
        </div>

        <div class="stat-card bg-gradient-to-br from-yellow-500 to-yellow-600 rounded-xl p-6 text-white">
            <div class="flex items-center justify-between mb-4">
                <div class="w-12 h-12 bg-white bg-opacity-20 rounded-lg flex items-center justify-center">
                    <i class="fas fa-clock text-2xl"></i>
                </div>
                <span class="text-3xl font-bold">5.2</span>
            </div>
            <p class="text-yellow-100">平均处理时长</p>
            <p class="text-xs text-yellow-200 mt-2">
                <i class="fas fa-arrow-down mr-1"></i>
                较上月缩短 0.8天
            </p>
        </div>

        <div class="stat-card bg-gradient-to-br from-purple-500 to-purple-600 rounded-xl p-6 text-white">
            <div class="flex items-center justify-between mb-4">
                <div class="w-12 h-12 bg-white bg-opacity-20 rounded-lg flex items-center justify-center">
                    <i class="fas fa-percentage text-2xl"></i>
                </div>
                <span class="text-3xl font-bold">92%</span>
            </div>
            <p class="text-purple-100">满意度</p>
            <p class="text-xs text-purple-200 mt-2">
                <i class="fas fa-arrow-up mr-1"></i>
                较上月提升 3%
            </p>
        </div>
    </div>

    <!-- 筛选条件 -->
    <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6 mb-6">
        <h3 class="text-lg font-semibold text-slate-800 mb-4">分析条件</h3>
        
        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <!-- 时间范围 -->
            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2">时间范围</label>
                <select class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    <option>全部时间</option>
                    <option>本月</option>
                    <option>上月</option>
                    <option>本季度</option>
                    <option>本年度</option>
                </select>
            </div>

            <!-- 信访类型 -->
            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2">信访类型</label>
                <select class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    <option>全部类型</option>
                    <option>环境污染</option>
                    <option>噪音扰民</option>
                    <option>市容管理</option>
                    <option>交通问题</option>
                    <option>其他</option>
                </select>
            </div>

            <!-- 区域选择 -->
            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2">区域选择</label>
                <select class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    <option>全部区域</option>
                    <option>福田区</option>
                    <option>罗湖区</option>
                    <option>南山区</option>
                    <option>宝安区</option>
                    <option>龙岗区</option>
                    <option>盐田区</option>
                </select>
            </div>
        </div>

        <div class="flex justify-end mt-4 space-x-3">
            <button class="px-6 py-2 border border-slate-300 rounded-lg hover:bg-slate-50 transition-colors">
                重置
            </button>
            <button class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
                开始分析
            </button>
        </div>
    </div>

    <!-- 统计图表 -->
    <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
        <!-- 趋势分析 -->
        <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
            <div class="flex items-center justify-between mb-6">
                <h3 class="text-lg font-semibold text-slate-800">信访趋势分析</h3>
                <div class="flex space-x-2">
                    <button class="px-3 py-1 text-sm bg-indigo-100 text-indigo-700 rounded-lg">月度</button>
                    <button class="px-3 py-1 text-sm hover:bg-slate-100 rounded-lg">季度</button>
                    <button class="px-3 py-1 text-sm hover:bg-slate-100 rounded-lg">年度</button>
                </div>
            </div>
            <div class="chart-container">
                <canvas id="trendChart"></canvas>
            </div>
        </div>

        <!-- 类型分布 -->
        <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
            <div class="flex items-center justify-between mb-6">
                <h3 class="text-lg font-semibold text-slate-800">类型分布</h3>
                <button class="text-sm text-indigo-600 hover:text-indigo-800">
                    <i class="fas fa-ellipsis-h"></i>
                </button>
            </div>
            <div class="chart-container">
                <canvas id="typeChart"></canvas>
            </div>
        </div>
    </div>

    <!-- 详细统计表格 -->
    <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
        <div class="flex items-center justify-between mb-6">
            <h3 class="text-lg font-semibold text-slate-800">详细统计</h3>
            <div class="flex space-x-2">
                <button class="px-4 py-2 text-sm border border-slate-300 rounded-lg hover:bg-slate-50">
                    <i class="fas fa-download mr-2"></i>导出
                </button>
            </div>
        </div>

        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-slate-50">
                    <tr>
                        <th class="text-left p-4 font-semibold text-slate-700">时间</th>
                        <th class="text-left p-4 font-semibold text-slate-700">信访总数</th>
                        <th class="text-left p-4 font-semibold text-slate-700">已处理</th>
                        <th class="text-left p-4 font-semibold text-slate-700">处理中</th>
                        <th class="text-left p-4 font-semibold text-slate-700">待处理</th>
                        <th class="text-left p-4 font-semibold text-slate-700">处理率</th>
                        <th class="text-left p-4 font-semibold text-slate-700">满意度</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-200">
                    <tr class="hover:bg-slate-50">
                        <td class="p-4 font-medium">2024年1月</td>
                        <td class="p-4 font-medium">156</td>
                        <td class="p-4 text-green-600">112</td>
                        <td class="p-4 text-yellow-600">32</td>
                        <td class="p-4 text-red-600">12</td>
                        <td class="p-4">71.8%</td>
                        <td class="p-4">4.5</td>
                    </tr>
                    <tr class="hover:bg-slate-50">
                        <td class="p-4 font-medium">2023年12月</td>
                        <td class="p-4 font-medium">134</td>
                        <td class="p-4 text-green-600">98</td>
                        <td class="p-4 text-yellow-600">28</td>
                        <td class="p-4 text-red-600">8</td>
                        <td class="p-4">73.1%</td>
                        <td class="p-4">4.3</td>
                    </tr>
                    <tr class="hover:bg-slate-50">
                        <td class="p-4 font-medium">2023年11月</td>
                        <td class="p-4 font-medium">189</td>
                        <td class="p-4 text-green-600">145</td>
                        <td class="p-4 text-yellow-600">36</td>
                        <td class="p-4 text-red-600">8</td>
                        <td class="p-4">76.7%</td>
                        <td class="p-4">4.6</td>
                    </tr>
                    <tr class="hover:bg-slate-50">
                        <td class="p-4 font-medium">2023年10月</td>
                        <td class="p-4 font-medium">223</td>
                        <td class="p-4 text-green-600">156</td>
                        <td class="p-4 text-yellow-600">45</td>
                        <td class="p-4 text-red-600">22</td>
                        <td class="p-4">69.9%</td>
                        <td class="p-4">4.2</td>
                    </tr>
                    <tr class="hover:bg-slate-50">
                        <td class="p-4 font-medium">2023年9月</td>
                        <td class="p-4 font-medium">198</td>
                        <td class="p-4 text-green-600">142</td>
                        <td class="p-4 text-yellow-600">38</td>
                        <td class="p-4 text-red-600">18</td>
                        <td class="p-4">71.7%</td>
                        <td class="p-4">4.4</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script src="/static/vendor/js/chart-4.5.0.js"></script>
<script>
    // 趋势分析图表
    const trendCtx = document.getElementById('trendChart').getContext('2d');
    const trendChart = new Chart(trendCtx, {
        type: 'line',
        data: {
            labels: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            datasets: [{
                label: '信访数量',
                data: [145, 132, 178, 156, 189, 223, 198, 167, 198, 223, 189, 134],
                borderColor: 'rgb(99, 102, 241)',
                backgroundColor: 'rgba(99, 102, 241, 0.1)',
                tension: 0.4,
                fill: true
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: false
                }
            },
            scales: {
                y: {
                    beginAtZero: true
                }
            }
        }
    });

    // 类型分布图表
    const typeCtx = document.getElementById('typeChart').getContext('2d');
    const typeChart = new Chart(typeCtx, {
        type: 'doughnut',
        data: {
            labels: ['环境污染', '噪音扰民', '市容管理', '交通问题', '其他'],
            datasets: [{
                data: [156, 134, 189, 223, 198],
                backgroundColor: [
                    'rgb(239, 68, 68)',
                    'rgb(245, 158, 11)',
                    'rgb(34, 197, 94)',
                    'rgb(59, 130, 246)',
                    'rgb(156, 163, 175)'
                ]
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    position: 'bottom'
                }
            }
        }
    });
</script>
{% endblock %}